<?php
require_once("../inc/bootstrap.php");

/* Check if a file exists on the server
   Parameters: id=post_id
   Return values: 1 if the file exists and isn't corrupted, otherwise 0
*/

if (empty($_GET['id']))
	{
		echo '0';
		exit;
	}
	$ID = intval($_GET['id']);
	$mysqli = dbconnect();
	$query = "SELECT Filehash FROM uploads WHERE ID=?";
	$statement = $mysqli->stmt_init();
$statement->prepare($query);
$statement->bind_param("i", $ID);
$statement->execute();
	if ($statement->num_rows == 1)
	{
		$filehash = dbresult($statement,0,0);
	}
	$statement->close();
	$mysqli->close();
	if (file_exists($uploadsDir.$ID) && hash_file('sha1',$uploadsDir.$ID,false) == $filehash)
	{
		echo '1';
		exit;
	}
	echo '0';
	exit;

?>